package com.unittec.zk.provider.auth.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.unittec.zk.provider.auth.entity.SysPermission;

import lombok.Data;

/**
 * @description 菜单Tree
 * @author Jason
 * @date 2019/11/07
 */
@Data
public class SysPermissionTree implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * 菜单id
     */
    private String id;
    /**
     * 父级id
     */
    private String parentId;
    /**
     * 菜单英文名称
     */
    private String name;
    /**
     * 菜单中文名称
     */
    private String nameZh;
    /**
     * 菜单路径
     */
    private String path;
    /**
     * 组件
     */
    private String component;
    /**
     * 组件名称
     */
    private String componentName;
    /**
     * 一级菜单跳转地址
     */
    private String redirect;
    /**
     * 菜单类型(0=一级菜单，1=子菜单，2=按钮权限)
     */
    private Integer menuType;
    /**
     * 菜单权限编码，例如：“sys:schedule:list,sys:schedule:info”,多个逗号隔开
     */
    private String perms;
    /**
     * 权限策略(1=启用，2=禁用)
     */
    private String permsType;
    /**
     * 菜单排序
     */
    private Integer sortNo;
    /**
     * 是否聚合子路由(0=否，1=是)
     */
    private boolean alwaysShow;
    /**
     * 菜单图标
     */
    private String icon;
    /**
     * 是否路由菜单(0=否，1=是)
     */
    @TableField(value = "is_route")
    private boolean route;
    /**
     * 是否叶子节点(0=是，1=否)
     */
    @TableField(value = "is_leaf")
    private boolean leaf;
    /**
     * 是否缓存该页面(0=否，1=是)
     */
    @TableField(value = "keep_alive")
    private boolean keepAlive;
    /**
     * 是否隐藏路由菜单(0=否，1=是)
     */
    private boolean hidden;
    /**
     * 描述
     */
    private String description;
    /**
     * 删除状态(0=正常，1=已删除)
     */
    private Integer delFlag;
    /**
     * 是否添加数据权限(0=否，1=是)
     */
    private Integer ruleFlag;
    /**
     * 按钮权限状态(0=有效，1=无效)
     */
    private Integer status;
    /**
     * 平台code，对于sys_application表app_code字段
     */
    private String platformCode;

    private String appId;

    private String tenantId;

    private String createUser;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    private String modifyUser;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date modifyTime;

    private List<SysPermissionTree> children;

    public SysPermissionTree() {

    }

    public SysPermissionTree(SysPermission permission) {
        this.id = permission.getId();
        this.parentId = permission.getParentId();
        this.name = permission.getName();
        this.nameZh = permission.getNameZh();
        this.perms = permission.getPerms();
        this.permsType = permission.getPermsType();
        this.alwaysShow = permission.isAlwaysShow();
        this.icon = permission.getIcon();
        this.component = permission.getComponent();
        this.path = permission.getPath();
        this.redirect = permission.getRedirect();
        this.sortNo = permission.getSortNo();
        this.menuType = permission.getMenuType();
        this.leaf = permission.isLeaf();
        this.route = permission.isRoute();
        this.keepAlive = permission.isKeepAlive();
        this.hidden = permission.isHidden();
        this.description = permission.getDescription();
        this.delFlag = permission.getDelFlag();
        this.ruleFlag = permission.getRuleFlag();
        this.status = permission.getStatus();
        this.platformCode = permission.getPlatformCode();
        this.appId = permission.getAppId();
        this.tenantId = permission.getTenantId();
        this.createUser = permission.getCreateUser();
        this.createTime = permission.getCreateTime();
        this.modifyUser = permission.getModifyUser();
        this.modifyTime = permission.getModifyTime();
        if (!permission.isLeaf()) {
            this.children = new ArrayList<SysPermissionTree>();
        }
    }
}
